<?php
class Cache
{
	/**
	 * The caching backend, usually memcache.
	 */
	static protected $backend;
	
	static public function connect()
	{
		if (!class_exists('Memcache')) {
			Event::log('framework.cache', 'Memcache extension not found, deactivating cache');
			return;
		}
		
		self::$backend = new Memcache;
		@$success = self::$backend->connect('localhost', 11211);
		
		if ($success) {
			Event::log('framework.cache', 'Connected to memcache');
		} else {
			Event::log('framework.cache', 'Could not connect to memcache, deactivating cache');
			self::$backend = null;
		}
	}
	
	static public function get($key)
	{
		if ($backend === null) return null;
		
		var_dump($result = $backend->get($key));
		
		Event::log('framework.cache', 'Fetching from cache: '.$key, Event::LOG_DEBUG);

		return $result;
	}
	
	static public function set($key, $value)
	{
		if ($backend === null) return;
		
		$backend->set($key, $value);
	}
}
?>